package csloader.loaders
{
	import com.adobe.utils.XMLUtil;
	
	import flash.events.Event;
	
	import csloader.events.ExtraEvent;

	public class XMLLoader extends TextLoaderBase
	{
		public function XMLLoader(callback:Function)
		{
			super(callback);
		}
		
		/**
		 * 验证返回的字符串是否为有效的XML对象
		 * @param url
		 * @param response
		 * 
		 */
		override public function sendResponse(url:String, response:*=null) : void
		{
			//响应错误，返回的数据不是XML对象
			if(!XMLUtil.isValidXML(response)) {
				callback.apply(null, [new ExtraEvent(Event.COMPLETE, url)]);
				trace("与 " + url + " 通讯时发生响应错误，错误代码：无效的XML对象。");
				return;
			}
			response = new XML(response);
			//发送响应成功事件
			super.sendResponse(url, response);
		}
	}
}